package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.testng.annotations.Test;

public class ContactCreationTests extends TestBase {

	

	public String generateRandomString() {
		Random rnd = new Random();
		if (rnd.nextInt(5) == 0) {
			return "";
		} else {
			return "firstname1" + rnd.nextInt();

		}
	}

	@Test(dataProvider = "randomValidContactGenerator")
	public void testContactCreationWithValidData(ContactData stringgroup)
			throws Exception {
		app.getNavigationHelper().openMainPage();
		app.getContactHelper().openContactPage();

		// save old state
		List<ContactData> oldList = app.getContactHelper().getContact();
		// actions

		app.getContactHelper().fillContactCreationForm(stringgroup);
		app.getContactHelper().submitContactCreation();
		app.getContactHelper().returnToHomePage();

		// save new state
		List<ContactData> newList = app.getContactHelper().getContact();

		// compare states
		oldList.add(stringgroup);
		Collections.sort(oldList);
		assertEquals(newList, oldList);

	}

}
